package cn.jy.ad.controller;

import cn.jy.ad.common.Result;
import cn.jy.ad.service.SplitAdvertisingService;
import cn.jy.common.ad.domain.ExpressSplitAdvertising;
import cn.jy.common.ad.domain.dto.ExpressSplitAdvertisingDto;
import cn.jy.common.ad.domain.vo.ExpressSplitAdvertisingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

@RestController
@RequestMapping("/split")
public class SplitAdvertisingController {
    @Autowired
    private SplitAdvertisingService splitAdvertisingService;

    @PostMapping("/list")
    public Result list(@RequestBody ExpressSplitAdvertisingVo vo) {
      vo.setOffset((vo.getPageNum() - 1) * vo.getPageSize());
      List<ExpressSplitAdvertisingDto> list = splitAdvertisingService.list(vo);
        Long count =Long.valueOf(splitAdvertisingService.count(vo));
        return Result.publicSuccess(count,list);
    }
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody ExpressSplitAdvertising splitAdvertising) {
        splitAdvertisingService.updateStatus(splitAdvertising);
        return Result.success();
    }
    @PostMapping("/addSplitAdvertising")
    public Result addSplitAdvertising(@RequestBody ExpressSplitAdvertising splitAdvertising) {
        splitAdvertisingService.addSplitAdvertising(splitAdvertising);
        return Result.success();
    }
    @PostMapping("/updateSplitAd")
    public Result updateSplitAd(@RequestBody ExpressSplitAdvertising splitAdvertising) {
        splitAdvertisingService.updateSplitAd(splitAdvertising);
        return Result.success();
    }
    @GetMapping("/findSplidAdById/{id}")
    public Result findSplidAdById(@PathVariable("id") Integer id) {
        ExpressSplitAdvertising splitAdvertising = splitAdvertisingService.selectSplidAdById(id);
        return Result.success(splitAdvertising);
    }

}
